package com.bijiawang.user.mapper;

import com.bijiawang.user.bean.Userinfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import javax.persistence.Entity;


@Mapper
public interface UserinfoMapper {


    public Userinfo findByPhoneNumber(String phoneNumber);

    public Userinfo findByUsername(String username);

    @Insert("INSERT INTO userinfo(username,passw,phonenumber,valid,authority,email) VALUES(#{username},#{passw},#{phonenumber},#{valid},#{authority},#{email})")
    public void addnew(Userinfo userinfo);


    public String queryByPhonenumber(String phonenumber);

    public String queryByUsername(String username);

    @Update("update userinfo set passw=#{pasw} where phonenumber=#{phonenumber}")
    void changepasw(String phonenumber,String pasw);

    @Update("update userinfo set username = #{newUsername} where username = #{oldUsername}")
    void changeUsername(String oldUsername,String newUsername);

    @Update("update userinfo set phoneNumber = #{newPhoneNumber} where phoneNumber = #{oldPhoneNumber}")
    void changePhoneNumber(String oldPhoneNumber,String newPhoneNumber);

    @Update("update userinfo set email = #{email} where username = #{username}")
    void changeEmail(String email,String username);
    
    @Select("SELECT email FROM userinfo where email = #{email}")
    String queryByEmail(String email);
}

